<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>InSTEDD | BioForms Offline Client</title>
    <link href="css/main.css" rel="stylesheet" type="text/css" />
  <!-- calendar stylesheet -->
  <link rel="stylesheet" type="text/css" media="all" href="css/calendar-win2k-cold-1.css" title="win2k-cold-1" />
  <!-- main calendar program -->
  <script type="text/javascript" src="js/calendar_stripped.js"></script>
  <!-- language for the calendar -->
  <script type="text/javascript" src="js/calendar-en.js"></script>

  <!-- the following script defines the Calendar.setup helper function, which makes
       adding a calendar a matter of 1 or 2 lines of code. -->
  <script type="text/javascript" src="js/calendar-setup_stripped.js"></script>
    <script type="text/javascript" src="js/forms-client.js"></script>
    <script type="text/javascript" src="js/forms-calculated-values.js"></script>
  <script type="text/javascript" src="js/validation.js"></script>
</head>
<body onload="loadDocument()">
    <xml ID="surveyXmlId" async="false" >
    </xml>
    <script type="text/javascript">        
        var fileSystemObject = top.fileSystemObject;
        var outboxFolder = getOutboxFolder(fileSystemObject);
        var sentFolder = getSentFolder(fileSystemObject);
        
        //var numberInputsToValidate =new Array("Saab","Volvo","BMW")
        
        var surveyFolderName; 
        var surveyPath;
        
        var defaultComment = ' (please provided any other information on this household that you believe to be relevant)';
        
        var dateFotmat = '%m-%d-%Y %H:%M';

        function loadDocument()
        {
            generateSurveyId();
            setDefaultDates();
            setDefaultComment('comments');
            setDefaultComment('followUpComments');
            generateSurveyPath();
        }
                
        function reloadDocument()
        {
            generateSurveyId();
            setDefaultDates();
            setDefaultComment('comments');
            setDefaultComment('followUpComments');
            generateRandomSurveyPath();
        }
        
        function activateTimeOfOnset()
        {
            if(document.getElementById('symptomsPresent').value == '0')
            {
                document.getElementById('timeOfOnset').value = '';
                document.getElementById('timeOfOnset').disabled = true;
                document.getElementById('timeOfOnset').className = 'readOnlyInput';
                document.getElementById('btnSelectFirstSickDate').disabled = true;
            } 
            else
            {
                //setDefaultDate('timeOfOnset', dateFotmat);
                document.getElementById('timeOfOnset').disabled = false;
                document.getElementById('timeOfOnset').className = 'regularTextbox';
                document.getElementById('btnSelectFirstSickDate').disabled = false;
            }
        }
        
        function cleanDefaultComment(commentElementId)
        {
            if(document.getElementById(commentElementId).value == defaultComment)
            {
                document.getElementById(commentElementId).value = '';
            }
        }
        
        function setDefaultComment(commentElementId)
        {
            if(document.getElementById(commentElementId).value == '')
            {
                document.getElementById(commentElementId).value = defaultComment;
            }
        }
                
        function generateSurveyId()
        {
            var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZ";
            //var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
            var string_length = 8;
            var randomstring = '';
            for (var i=0; i<string_length; i++) {
	            var rnum = Math.floor(Math.random() * chars.length);
	            randomstring += chars.substring(rnum,rnum+1);
            }
            document.getElementById('id').value = randomstring;
        }
        
        function generateSurveyPath()
        {
            surveyFolderName = getQueryVariable('surveyFolder');
            if(surveyFolderName == 'sent')
            {
                surveyPath = sentFolder + '\\' + getQueryVariable('surveyFile');
            }
            else if(surveyFolderName == 'outbox')
            {
                surveyPath = outboxFolder + '\\' + getQueryVariable('surveyFile');
            }
            
            if(surveyPath)
            {
                document.getElementById('surveyXmlId').src = surveyPath;
            }
            else
            {
                generateRandomSurveyPath();
            }
        }
        
        function generateRandomSurveyPath()
        {
                surveyPath = outboxFolder + '\\' + fileSystemObject.GetTempName() + '.survey.xml';
        }        
       
        function getQueryVariable(variable) 
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) 
            {
                var pair = vars[i].split("=");
                if (pair[0] == variable) 
                {
                    return pair[1];
                }
            }
            
            return null;
        } 
        
        function WriteXmlSurvey(surveyStream)
        {
            var doc = new ActiveXObject("Microsoft.XMLDOM");
            
            var root = doc.createElement('Survey');
            doc.appendChild(root);

            var versionAttribute = doc.createAttribute('version');
            versionAttribute.value = getSurveyVersion();
            root.setAttributeNode(versionAttribute);

            for(var enumerator = new Enumerator(document.getElementsByName('surveyInput')); !enumerator.atEnd(); enumerator.moveNext())
            {
                var element = enumerator.item();

                var surveyNameElement = doc.createElement(element.id);
                var surveyNameText = doc.createTextNode(element.value);
                surveyNameElement.appendChild(surveyNameText);
                root.appendChild(surveyNameElement);
            }

            surveyStream.WriteLine(doc.xml);
        }       
        
        // Show notes section (the notes are displayed when the element value is higher than 0)
        
        function showNote(thisElementId, noteElementId)
        {
            if(parseIntByElementId(thisElementId) > 0)
            {
                document.getElementById(noteElementId).style.visibility = 'visible'
            }
            else
            {
                document.getElementById(noteElementId).style.visibility = 'hidden'
            }
        }        
    </script>
    <div class="formTitle">Public Health Biosurveillance Forms</div>
    <div class="formVersion">version 21</div>
    <form id="mainForm" onsubmit="return false;" method="post">
    <div class="formLeftColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">HOUSEHOLD</legend>
    <label class="lblCaption">Survey ID</label>
    <input class="regularTextbox readOnlyInput" type="text" maxlength="8" name="surveyInput" id="id" datasrc="#surveyXmlId" datafld="id" readonly="readonly" />
    <label class="lblCaption">Entered by</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="enteredBy" datasrc="#surveyXmlId" datafld="enteredBy" />
    <label class="lblCaption">Entered on<span class="inputSample">&nbsp;(mm/dd/yyyy hh:mm)</span></label>
    <input class="regularTextbox" type="text" name="surveyInput" id="enteredOn" datasrc="#surveyXmlId" datafld="enteredOn" /><input id="btnSelectEnterdOnDate" style="padding-left:4px" type="image" src="img/calendar.gif" />
    </fieldset>
    </div>
    <div class="formRightColumn">
    <fieldset class="formFieldset">
    <label class="lblCaption">Latitude<span class="inputSample">&nbsp;(e.g. 37.437)</span></label>
    <input class="regularTextbox" type="text" name="surveyInput" id="latitude" datasrc="#surveyXmlId" datafld="latitude"/>
    <label class="lblCaption">Longitude<span class="inputSample">&nbsp;(e.g. -122.159)</span></label>
    <input class="regularTextbox" type="text" name="surveyInput" id="longitude" datasrc="#surveyXmlId" datafld="longitude"/>
    <span class="lblCaption" id="addressFoundMessage" style="display:block;color:red;width:250px"><br />Please enter LatLong OR an address below.</span>
    </fieldset>
    </div>
    <div class="newRow"></div>
    <div class="formLeftColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">SOURCE</legend>
    <label class="lblCaption">First Name</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="firstName" datasrc="#surveyXmlId" datafld="firstName"/>
    <label class="lblCaption">Last Name</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="lastName" datasrc="#surveyXmlId" datafld="lastName"/>
    <label class="lblCaption">Primary Phone Number</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="phone1" datasrc="#surveyXmlId" datafld="phone1"/>
    <label class="lblCaption">Email Address</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="email" datasrc="#surveyXmlId" datafld="email"/>
    </fieldset>
    </div>
    <div class="formRightColumn">
    <fieldset class="formFieldset">
    <label class="lblCaption">Address</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="streetAddress" datasrc="#surveyXmlId" datafld="streetAddress"/>
    <label class="lblCaption">City</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="city" datasrc="#surveyXmlId" datafld="city"/>
    <label class="lblCaption">State</label>
    <select name="surveyInput" id="state" datasrc="#surveyXmlId" datafld="state" >
        <option value="AL">AL</option>
        <option value="AK">AK</option>
        <option value="AZ">AZ</option>
        <option value="AR">AR</option>
        <option selected="selected" value="CA">CA</option>
        <option value="CO">CO</option>
        <option value="CT">CT</option>
        <option value="DE">DE</option>
        <option value="FL">FL</option>
        <option value="GA">GA</option>
        <option value="HI">HI</option>
        <option value="ID">ID</option>
        <option value="IL">IL</option>
        <option value="IN">IN</option>
        <option value="IA">IA</option>
        <option value="KS">KS</option>
        <option value="KY">KY</option>
        <option value="LA">LA</option>
        <option value="ME">ME</option>
        <option value="MD">MD</option>
        <option value="MA">MA</option>
        <option value="MI">MI</option>
        <option value="MN">MN</option>
        <option value="MS">MS</option>
        <option value="MO">MO</option>
        <option value="MT">MT</option>
        <option value="NE">NE</option>
        <option value="NV">NV</option>
        <option value="NH">NH</option>
        <option value="NJ">NJ</option>
        <option value="NM">NM</option>
        <option value="NY">NY</option>
        <option value="NC">NC</option>
        <option value="ND">ND</option>
        <option value="OH">OH</option>
        <option value="OK">OK</option>
        <option value="OR">OR</option>
        <option value="PA">PA</option>
        <option value="RI">RI</option>
        <option value="SC">SC</option>
        <option value="SD">SD</option>
        <option value="TN">TN</option>
        <option value="TX">TX</option>
        <option value="UT">UT</option>
        <option value="VT">VT</option>
        <option value="VA">VA</option>
        <option value="WA">WA</option>
        <option value="WV">WV</option>
        <option value="WI">WI</option>
        <option value="WY">WY</option>
    </select>
    <label class="lblCaption">Zip Code</label>
    <input class="regularTextbox" type="text" name="surveyInput" id="postalCode" datasrc="#surveyXmlId" datafld="postalCode"/>
    </fieldset>
    </div>
    <!-- OCCUPANT'S EXPOSURE & STATUS section -->
    <div class="newRow"></div>
    <div class="formSingleColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">OCCUPANT'S EXPOSURE & STATUS</legend>
    <div class="singleLineQuestion"><span class="lblQuestion">How many people are currently living at this address?</span><input class="shortTextbox" type="text" validate="number" name="surveyInput" id="totalOccupants" datasrc="#surveyXmlId" datafld="totalOccupants" onchange="showCalculatedValues()"/></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants attended the concert?</span><input class="shortTextbox" type="text" name="surveyInput" validate="number" id="attendedConcert" onchange="showCalculatedValues(showTotalExposed())" datasrc="#surveyXmlId" datafld="attendedConcert" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants who did <b>not</b> attend the concert have been in <b>close contact</b> with anyone who <b>did</b> attend the concert?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="attendeeContact" datasrc="#surveyXmlId" datafld="attendeeContact" onchange="showCalculatedValues(showTotalExposed())" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants have developed either <b>fever</b> or a <b>severe bloody cough</b> since the concert? </span><input class="shortTextbox" type="text" validate="number" name="surveyInput" onkeyup="showNote('symptomsPresent', 'symptomsPresentNote')" onchange="showCalculatedValues(showTotalExposed());activateTimeOfOnset()" id="symptomsPresent" datasrc="#surveyXmlId" datafld="symptomsPresent" /><span id="symptomsPresentNote" class="validationMessage">NOTE: Please refer these people to IV Treatment immediately</span></div>
    <div class="singleLineQuestion"><span class="lblQuestion">When did the <b>"FIRST SICK"</b> occupant develop symptoms?</span><input class="regularTextbox" type="text" name="surveyInput" id="timeOfOnset" datasrc="#surveyXmlId" datafld="timeOfOnset"  /><input id="btnSelectFirstSickDate" style="padding-left:4px" type="image" src="img/calendar.gif" /><span class="inputSample">&nbsp;(mm/dd/yyyy hh:mm)</span></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants who became ill following the concert have died?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="deceased" datasrc="#surveyXmlId" datafld="deceased" onchange="showCalculatedValues(showTotalExposed())"   /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants have been exposed in this household?</span><input class="shortTextbox readOnlyInput" tabindex="-1" type="text" id="totalExposed" value="0" readonly="readonly" /></div>
    </fieldset>
    </div>
    <!-- PROPHYLAXIS TYPE section -->
    <div class="newRow"></div>
    <div class="formSingleColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">PROPHYLAXIS TYPE</legend>
    <span class="lblQuestion">ONLY COMPLETE THIS SECTION IF <b>EXPOSURE</b> HAS OCCURRED <b>AND NOT ILL</b></span>
    <div class="warningNote">NOTE: UNLESS young, pregnant, or allergic, give Doxycycline 100mg by mouth twice a day for ten days.</div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants are <b>under 9 years old</b>?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="under9years" datasrc="#surveyXmlId" datafld="under9years" onkeyup="showNote('under9years', 'under9yearsNote')"  onchange="showCalculatedValues(showTotCiproDist())" /><span id="under9yearsNote" class="validationMessage">NOTE: Please give <b>Cipro</b> and refer to guidelines because the dose is by weight</span></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants are <b>pregnant</b>?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="pregnant" datasrc="#surveyXmlId" datafld="pregnant" onkeyup="showNote('pregnant', 'pregnantNote')"  onchange="showCalculatedValues(showTotCiproDist())" /><span id="pregnantNote" class="validationMessage">NOTE: Please give <b>Cipro 500mg by mouth twice a day for ten days</b></span></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants <b>not pregnant</b> and <b>at least 9 years old</b> are <b>allergic</b> to Doxycycline, Tetracycline or Minocycline?</span><input class="shortTextbox" validate="number" type="text" name="surveyInput" id="allergicDoxy" datasrc="#surveyXmlId" datafld="allergicDoxy" onkeyup="showNote('allergicDoxy', 'allergicDoxyNote')"  onchange="showCalculatedValues(showTotCiproDist())"  /><div class="lblQuestion">(allergic reactions include: rashes, difficulty breathing, seizure, and passing out)</div><span id="allergicDoxyNote" class="validationMessage">NOTE: Please give <b>Cipro 500mg by mouth twice a day for ten days</b></span></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total Cipro 500mg tablets to distribute:</span><input class="shortTextbox readOnlyInput" type="text" id="totCiproDist" tabindex="-1" readonly="readonly" name="surveyInput" datasrc="#surveyXmlId" datafld="totCiproDist" /><span class="lblQuestion">(20 tabs per person for <b>vulnerable</b> prophylaxis)</span></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total Doxy 100mg tablets to distribute:</span><input class="shortTextbox readOnlyInput" type="text" id="totDoxyDist" tabindex="-1" readonly="readonly" name="surveyInput" datasrc="#surveyXmlId" datafld="totDoxyDist" /><span class="lblQuestion">(20 tabs per person for <b>normal</b> prophylaxis)</span></div>
    </fieldset>
    </div>
    <!-- ACTIONS TAKEN section -->
    <div class="newRow" />
    <div class="formSingleColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">ACTIONS TAKEN</legend>
    <div class="singleLineQuestion"><span class="lblQuestion">How many courses (sets of 20 tablets) of Cipro were distributed?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="ciproDistributed" datasrc="#surveyXmlId" datafld="ciproDistributed" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many courses (sets of 20 tablets) of Doxy were distributed?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="doxyDistributed" datasrc="#surveyXmlId" datafld="doxyDistributed" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Comments:</span><div style="clear:both" /><textarea class="formTextArea" name="surveyInput" id="comments" datasrc="#surveyXmlId" datafld="comments" onblur="setDefaultComment('comments')" onfocus="cleanDefaultComment('comments')" ></textarea></div>
    </fieldset>
    </div>
    <!-- FOLLOW-UP section -->
    <div class="newRow" />
    <div class="formSingleColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">FOLLOW-UP</legend>
    <div class="singleLineQuestion"><span class="lblQuestion">Entered on</span><input class="regularTextbox" type="text" name="surveyInput" id="followUpEnteredOn" datasrc="#surveyXmlId" datafld="followUpEnteredOn" /><input id="btnSelectFollowUpEnterdOnDate" style="padding-left:4px" type="image" src="img/calendar.gif" /><span class="inputSample">&nbsp;(mm/dd/yyyy hh:mm)</span>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants received IV treatment?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="receivedIvTreatment" onchange="showTotTx()" datasrc="#surveyXmlId" datafld="receivedIvTreatment" onchange=showCalculatedValues(receivedIvTreatment)" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants have had allergic reactions to Cipro or Doxy?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="doxyciproAllergy" datasrc="#surveyXmlId" datafld="doxyciproAllergy" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">How many occupants who became ill following the concert have recovered from their illness since  your last visit?</span><input validate="number" class="shortTextbox" type="text" name="surveyInput" id="recovered" datasrc="#surveyXmlId" datafld="recovered" onchange="showCalculatedValues(showTotRecover())" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Comments:</span><div style="clear:both" /><textarea class="formTextArea" name="surveyInput" id="followUpComments" datasrc="#surveyXmlId" datafld="followUpComments" onblur="setDefaultComment('followUpComments')" onfocus="cleanDefaultComment('followUpComments')" ></textarea></div>
    </fieldset>
    </div>
    <div class="newRow" />
    <hr class="lineBreak" />
    <!-- CALCULATED NUMERIC VALUES (read-only) section -->
    <div class="newRow" />
    <div class="formSingleColumn">
    <fieldset class="formFieldset"><legend class="sectionCaption">CALCULATED NUMERIC VALUES (read-only)</legend>
    <div class="singleLineQuestion"><span class="lblQuestion">Total well (not exposed not ill)</span><input id="totWell" class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" name="surveyInput" datasrc="#surveyXmlId" datafld="totWell" /></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total Exposed</span><input class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" id="totExposed" name="surveyInput" datasrc="#surveyXmlId" datafld="totExposed"/></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total Exposed not Ill</span><input class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" id="totExpNotIll" name="surveyInput" datasrc="#surveyXmlId" datafld="totExpNotIll"/></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total Exposed and Ill</span><input class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" id="totExpIll" name="surveyInput" datasrc="#surveyXmlId" datafld="totExpIll"/></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total received treatment</span><input class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" id="totTx" name="surveyInput" datasrc="#surveyXmlId" datafld="totTx"/></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total recovered</span><input class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" id="totRecover" name="surveyInput" datasrc="#surveyXmlId" datafld="totRecover"/></div>
    <div class="singleLineQuestion"><span class="lblQuestion">Total deceased</span><input class="shortTextbox readOnlyInput" type="text" tabindex="-1" readonly="readonly" id="totDeceased" name="surveyInput" datasrc="#surveyXmlId" datafld="totDeceased"/></div>
    </fieldset>
    <input type="button" class="button" value="Save" onclick="SaveSurvey()" />
    <br /><br />
  </div>
  </form>
    
    <script type="text/javascript">
     function setDefaultDates()
     {
        setDefaultDate('enteredOn', dateFotmat);
        //setDefaultDate('timeOfOnset', dateFotmat);
        //setDefaultDate('followUpEnteredOn', dateFotmat);
     }   
    
     function setDefaultDate(elementId, format)
     {
        document.getElementById(elementId).value = new Date().print(format); 
     }   
    
     Calendar.setup({
            inputField     :    "enteredOn",       // id of the input field
            ifFormat       :    dateFotmat,       // format of the input field
            timeFormat     :    "24",
            showsTime      :    true,
            button         :    "btnSelectEnterdOnDate",   // trigger for the calendar (button ID)
            align          :    "Tl",              // alignment (defaults to "Bl")
            singleClick    :    true
        });
        Calendar.setup({
            inputField     :    "timeOfOnset",       // id of the input field
            ifFormat       :    dateFotmat,       // format of the input field
            timeFormat     :    "24",
            showsTime      :    true,
            button         :    "btnSelectFirstSickDate",   // trigger for the calendar (button ID)
            align          :    "Tl",              // alignment (defaults to "Bl")
            singleClick    :    true
        });
        Calendar.setup({
            inputField     :    "followUpEnteredOn",       // id of the input field
            ifFormat       :    dateFotmat,       // format of the input field
            timeFormat     :    "24",
            showsTime      :    true,
            button         :    "btnSelectFollowUpEnterdOnDate",   // trigger for the calendar (button ID)
            align          :    "Tl",              // alignment (defaults to "Bl")
            singleClick    :    true
        });
    </script>
    
    <script language="javascript" type="text/javascript">
    
        function ValidateSurveyNumberInputs()
        {
            for(var enumerator = new Enumerator(document.getElementsByName('surveyInput')); !enumerator.atEnd(); enumerator.moveNext())
            {
                var element = enumerator.item();
            
                if(element.getAttribute('validate') == 'number' && element.value != '' && !validateNumber(element.value))
                {
                    alert('The input ' + element.Id + ' has an invalid numeric value.');
                    return false;
                }
            }
            
            return true;
        }

        function SaveSurvey()
        {             
            // enforce we have LatLong or an Address at least
            if(!validateLatLongAddress(document.getElementById("latitude").value, document.getElementById("longitude").value, document.getElementById("streetAddress").value))
            {
                    alert("Please provide LatLong coordinates or a Postal Address");
                    return;
            }
            
            if(!validateDate(document.getElementById("enteredOn").value))
            {
                alert("The 'Entered On' date is invalid. Please check if it is compliant with the format mm/dd/yyyy hh:mm and try again.");
                return;
            }

            if(document.getElementById("timeOfOnset").value != '' && !validateDate(document.getElementById("timeOfOnset").value))
            {
                alert("The 'FIRST SICK' date is invalid. Please check if it is compliant with the format mm/dd/yyyy hh:mm and try again.");
                return;
            }

            if(document.getElementById("followUpEnteredOn").value != '' && !validateDate(document.getElementById("followUpEnteredOn").value))
            {
                alert("The 'Follow up Entered on' date is invalid. Please check if it is compliant with the format mm/dd/yyyy hh:mm and try again.");
                return;
            }
            
            if(!ValidateSurveyNumberInputs())
            {
                return;
            }
                                    
            cleanDefaultComment('comments');
            cleanDefaultComment('followUpComments');
           
            var surveyStream = fileSystemObject.OpenTextFile(surveyPath, 2, true, 0);
            WriteXmlSurvey(surveyStream);
            surveyStream.Close();

            if(surveyFolderName == 'sent')
            {
                var surveyFile = fileSystemObject.GetFile(surveyPath);
                fileSystemObject.MoveFile(surveyPath, outboxFolder + '\\' + surveyFile.Name);
//                alert('The survey was successfully updated and moved to the outbox to be resent');
                window.location.href = 'Outbox.htm';
            }
            else if(surveyFolderName == 'outbox')
            {
//                alert('The survey was succesfully updated at ' + surveyPath);            
                window.location.href = 'Outbox.htm';
            }
            else
            {
//                alert('The survey was successfully created at ' + surveyPath);
            }
                        
           top.RefreshOuboxAndSentLabels();

            // reset all the fields but the EnteredBy one
            var enteredByElem = document.getElementById('enteredBy');
            var enteredByValue = enteredByElem.value;
            mainForm.reset();
            reloadDocument();
            enteredByElem.value = enteredByValue;            
            
            top.document.getElementById('topAnchor').focus();
        }
    </script>
</body>
</html>
